package com.xing.binbackend.file;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.handler.CellWriteHandler;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

public class EasyExcelService {

    private static final String DIR = "";

    public void readFile(String fileName, String sheetName, List<TrafficRuleExcel> firewallRules) {
//        firewallRules.sort(Comparator.nullsLast(Comparator.comparing(rule -> {
//            String clientServiceName = ((TrafficRuleVO) rule).getClientCloudServiceName();
//            return clientServiceName == null ? "" : clientServiceName;
//        }).thenComparing(rule -> {
//            String serverServiceName = ((TrafficRuleVO) rule).getServerCloudServiceName();
//            return serverServiceName == null ? "" : serverServiceName;
//        })));
        String fullPath = DIR + File.separator + fileName;
        try (FileOutputStream fos = new FileOutputStream(fullPath)) {
            CellWriteHandler writeHandler = new AutoWrapCellWriteHandler(Arrays.asList("clientIps", "serverIps", "serverPorts"));
            CellWriteHandler writeHandler2 = new AutoWrapCellWriteHandler(Arrays.asList("clientIps", "serverIps", "serverPorts"));
            EasyExcel.write(fos, TrafficRuleExcel.class).registerWriteHandler(writeHandler).registerWriteHandler(writeHandler2).sheet(sheetName).head(TrafficRuleExcel.class).doWrite(firewallRules);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}



